<?php
require_once 'includes/config.php';
require_once 'classes/class.getter.php';
$getter = new Getter();

require_once 'classes/class.browse.php';

if(isset($_POST['browse_bar'])) {
	header('Location: ?path=' . $_POST['current_folder']);
}

if($getter->get("path") != "empty") {
	$strPath = $getter->get("path");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!--
***********************************
** By: Bram Mittendorff          **
***********************************
-->
<head>
<title>Sort Your Music</title>
	<link rel="stylesheet" type="text/css" href="css/music_sorter.css" />
	<!--[if lte IE 6]><link rel="stylesheet" type="text/css" href="css/music_sorter_png.css" /><![endif]-->
	<?php
	echo '<link rel="stylesheet" type="text/css" href="classes/class.browse.css.php" />';
	?>
	
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<meta http-equiv="imagetoolbar" content="no" />
	<meta name="keywords" content="" />
	<meta name="description" content="" />
	<meta name="robots" content="index, follow" />
</head>
<body>

	<div id="container">
		
		<div id="header">
			<ul>
				<li><a href="index.php">home</a></li>
			</ul>
		</div>
		
		<div id="content">
			<div id="sub">
				<h1>Home</h1>				
<?php
$starttime = getmicrotime();
$newBrowse = new Browse();
$newBrowse->setDir($strPath);

echo '<div class="browse_bar">' . CR_LF;
echo '	<form action="#" method="post" name="goto_folder">' . CR_LF;
echo '	<input type="text" name="current_folder" value="' . $strPath . '" />' . CR_LF;
echo '	<input type="hidden" name="browse_bar" value="submitted" />' . CR_LF;
echo '	</form>' . CR_LF;
echo '	<a href="javascript:document.goto_folder.submit();"><img src="icons/action_forward.gif" border="0" alt="" /></a>' . CR_LF;
echo '</div>' . CR_LF;

/*
Icons on top
*/
echo '<table cellspacing="0" cellpadding="0" border="0" class="table_top">' . CR_LF;
echo '<tr>' . CR_LF;
if($getter->get("path") != "empty") {
	echo '	<th class="icons_top space_right"><a href="javascript:history.back(-1);"><img src="icons/action_back.gif" border="0" alt="Back" /></a></th>' . CR_LF;
}
if($getter->get("action") == "empty") {
echo '	<th class="icons_top"><a href="?path=' . $strPath . '&amp;action=new_folder"><img src="icons/folder_add.png" border="0" alt="New folder" /></a></th>' . CR_LF;
}
echo '</tr>' . CR_LF;
echo '</table>' . CR_LF . CR_LF;

if(stristr($getter->get("action"), "bulk") != "") {
	echo '<form method="post" action="actions.php" name="center_form">'. CR_LF;
}
switch ($getter->get("action")) {
    case "empty":
        $newBrowse->getDir($strPath);
        break;
    case "single_rename":
        $newBrowse->renameSingle($strPath);
        break;
    case "single_delete":
    	$newBrowse->deleteSingle($strPath);
    	break;
}

if(stristr($getter->get("action"), "bulk") != "") {
	echo '</form>'. CR_LF . CR_LF;
}

if($getter->get("action") == "empty") {
	/*
	Select options
	*/
	echo '<table cellspacing="0" cellpadding="0" border="0" class="table_bottom">' . CR_LF;
	echo '<tr>' . CR_LF;
	echo '	<th class="icons_bottom" style="padding: 0px 0px 0px 18px;"><img src="icons/arrow_turn_top.png" border="0" alt="Select all" /></th>' . CR_LF;
	echo '	<th class="icons_bottom space_left"><a href="?path=' . $strPath . '&amp;option=select_all">Select all</a> / <a href="?path=' . $strPath . '&amp;option=deselect_all">Deselect all</a></th>' . CR_LF;
	echo '	<th class="icons_bottom space_left">Bulk options: <a href="?path=' . $strPath . '&amp;action=bulk_rename"><img src="icons/table_edit.png" border="0" alt="Bulk rename" /></a> <a href="?path=' . $strPath . '&amp;action=bulk_delete"><img src="icons/table_delete.png" border="0" alt="Bulk delete" /></a></th>';
	echo '</tr>' . CR_LF;
	echo '</table>' . CR_LF . CR_LF;
}

$endtime = getmicrotime();
?>
				
				<p class="scanning">Scanned in: <?php echo number_format($endtime - $starttime, 3) . ' seconds'; ?></p>
			</div>
		</div>
		
	</div>

</body>
</html>